package pl.elka.simulator.gui.swt.painting;

import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.GC;

import pl.elka.simulator.core.IPaintable;
import pl.elka.simulator.core.Node;
import pl.elka.simulator.core.Pair;
import pl.elka.simulator.gui.swt.PositionConverter;

public class NodePainter implements IElementPainter{

	private Color paintingColor = null;
	
	@Override
	public void paint(IPaintable paintable,PaintEvent e) {		
		GC gc = e.gc;
		if(paintingColor==null){
			paintingColor = new Color(e.display, 105, 21, 189);
		}
	    gc.setBackground(paintingColor);
	    
		Node n = (Node) paintable;
		Pair<Integer, Integer> pos = PositionConverter.convertFromPosition(n.getPosition());
		int rx = PositionConverter.convertToScreenW(n.getRadius());
		int ry = PositionConverter.convertToScreenH(n.getRadius());
		gc.fillOval(pos.left-rx/2, pos.right - ry/2, rx, ry);				
	}

}
